package com.bw.product.server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ProductThreadPoolConfig {

//    @Bean(name = "itemThreadPoolExcuter")
//    public ThreadPoolExecutor itemThreadPoolExcuter(ItemThreadPoolProperties itemThreadPoolProperties){
//
//        return new ThreadPoolExecutor(
//                //java查吗
//                itemThreadPoolProperties.getCorePoolSize(),
//                itemThreadPoolProperties.getMaxPoolSize(),   //魔法值
//                itemThreadPoolProperties.getKeepAliveTime(),
//                TimeUnit.MINUTES,
//                new LinkedBlockingDeque<>(itemThreadPoolProperties.getQueueLength()),
//                Executors.defaultThreadFactory(),
//                new ThreadPoolExecutor.AbortPolicy()
//        );
//    }

    @Bean(name = "itemThreadPoolExcuter")
    public ThreadPoolExecutor itemThreadPoolExcuter(){

        return new ThreadPoolExecutor(
                //java查吗
                9,
                20,
                5,
                TimeUnit.MINUTES,
                new LinkedBlockingDeque<>(300),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

}
